package com.ruoyi.business.controller;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.AppCustomer;
import com.ruoyi.business.service.IAppCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author CuiYingJie
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/business/customer")
public class AppCustomerController extends BaseController
{
    @Autowired
    private IAppCustomerService appCustomerService;

    /**
     * 查询客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppCustomer appCustomer)
    {
        startPage();
        List<AppCustomer> list = appCustomerService.selectAppCustomerList(appCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:customer:export')")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppCustomer appCustomer)
    {
        List<AppCustomer> list = appCustomerService.selectAppCustomerList(appCustomer);
        ExcelUtil<AppCustomer> util = new ExcelUtil<>(AppCustomer.class);
        return util.exportExcel(list, "customer");
    }

    /**
     * 获取客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(appCustomerService.selectAppCustomerById(id));
    }

    /**
     * 新增客户信息
     */
    @PreAuthorize("@ss.hasPermi('business:customer:add')")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppCustomer appCustomer)
    {
        return toAjax(appCustomerService.insertAppCustomer(appCustomer));
    }

    /**
     * 修改客户信息
     */
    @PreAuthorize("@ss.hasPermi('business:customer:edit')")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppCustomer appCustomer)
    {
        return toAjax(appCustomerService.updateAppCustomer(appCustomer));
    }

    /**
     * 删除客户信息
     */
    @PreAuthorize("@ss.hasPermi('business:customer:remove')")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(appCustomerService.deleteAppCustomerByIds(ids));
    }

    /**
     * 手动充值/手动扣款
     */
    @Log(title = "客户信息", businessType = BusinessType.BALANCE)
    @PutMapping("/balanceEdit")
    public AjaxResult balanceEdit(@RequestBody Map<String, String> data){

        return toAjax(appCustomerService.updateBalanceByUserId(data));
    }

    /**
     * 封禁用户
     */
    @Log(title = "客户信息", businessType = BusinessType.LIMIT)
    @PutMapping("/limitCustomer")
    public AjaxResult limitCustomer(@RequestBody Map<String, String> data){

        return toAjax(appCustomerService.limitCustomer(data));
    }
}
